package com.gln.bloger.dao.impl;

import java.util.List;

import org.hibernate.Hibernate;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.gln.bloger.pojos.Entry;

public class TestEntryDaoImpl extends HibernateDaoSupport{
	@SuppressWarnings("unchecked")
	public List<Entry> loadAll(){
		List<Entry> entries = (List<Entry>)getHibernateTemplate().loadAll(Entry.class);
		for(Entry e: entries){
		    Hibernate.initialize(e.getAuthor());
		    Hibernate.initialize(e.getCategory());
		    System.out.print(e.getCategory().getName());
		}
		return entries;
	}
	
	public Entry get(String id){
		Entry entry = (Entry)getHibernateTemplate().get(Entry.class, id);
			Hibernate.initialize(entry.getAuthor());
		    Hibernate.initialize(entry.getCategory());
		    System.out.print(entry);
		return entry;
	}

	public static void main(String [] args){
		ApplicationContext ctx=new  
		FileSystemXmlApplicationContext("webRoot/WEB-INF/config/spring/testbeans.xml");
	    TestEntryDaoImpl edao = (TestEntryDaoImpl)ctx.getBean("testEntryDao");
	    @SuppressWarnings("unused")
		Entry entry = edao.get("2c9083ad1aec04f5011aec06a57b0001");
//	    List<Comment> comments = cdao.loadAll();
	}
}
//entry id 2c9083ad1aec04f5011aec06a57b0001
//comment id 2c9083ad1a9a182d011a9a19175c0001